package no.ntnu.fp.watch.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;

import no.ntnu.fp.model.Platform;
import no.ntnu.fp.model.Well;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class StatusPanel extends SuperStatusPanel
{
	private JButton realTimeCommentButton;
	private JButton EventlogButton;
	private JButton AlarmButton;
	private JLabel statusLabel;
	
	private RealTimeCommentDialog realTimeCommentDialog;
	
	
	/**
	 * Parent component.
	 */
	private platformPanel platformPanel;
	
	public StatusPanel(){
		
		
	}

	public StatusPanel(platformPanel platformPanel, int width, int height)
	{	
		this.platformPanel = platformPanel;
		this.setSize(new java.awt.Dimension(width, height));
		this.setPreferredSize(new Dimension(width, height));
		
		String text = "<html> <h2>Last status change</h2> <br>" +
				" Status duration: <br>" +
				"Time of change: <br><br><br><br>" +
				"Previous Status: </html> ";
		JLabel textLabel = new JLabel(text);
		textLabel.setSize(this.getWidth(), this.getHeight());
		add(textLabel);
		{
			statusLabel = new JLabel();
			statusLabel.setOpaque(true);
			statusLabel.setBackground(Color.red);
			statusLabel.setPreferredSize(new java.awt.Dimension(216, 37));
			this.add(statusLabel);
		}
		{
			AlarmButton = new JButton();
			this.add(AlarmButton);
			AlarmButton.setText("Alarm");
			AlarmButton.setPreferredSize(new java.awt.Dimension(216, 40));
			Icon AlarmIcon = new ImageIcon(getClass().getResource("Ikoner/alarmIcon.png"));
			AlarmButton.setIcon(AlarmIcon);
			AlarmButton.addActionListener(new AlarmButtonListener());
		}
		{
			EventlogButton = new JButton();
			this.add(EventlogButton);
			EventlogButton.setText("Eventlog");
			EventlogButton.setPreferredSize(new java.awt.Dimension(216, 40));
			Icon LogIcon = new ImageIcon(getClass().getResource("Ikoner/logBook.png"));
			EventlogButton.setIcon(LogIcon);
			EventlogButton.addActionListener(new EventLogButtonListener());
		}
		{
			realTimeCommentButton = new JButton();
			this.add(realTimeCommentButton);
			realTimeCommentButton.setText("Real-time Comment");
			realTimeCommentButton.setPreferredSize(new java.awt.Dimension(216, 40));
			Icon GraphIcon = new ImageIcon(getClass().getResource("Ikoner/graphIcon.png"));
			realTimeCommentButton.setIcon(GraphIcon);
			realTimeCommentButton.addActionListener(new RealTimeCommentButtonListener());
		}

	}
	
	public void setLastStatus(Color c){
		this.statusLabel.setBackground(c);
	}
	
	class EventLogButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e) 
		{
			Well w = (Well)platformPanel.getPlatform().getWell(platformPanel.getSelectedElement());

			JFrame eventLog = new EventLog(w, platformPanel.getPlatform());
		}
	}
	
	class AlarmButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			int selected = platformPanel.getSelectedElement();
			int n = 
				JOptionPane.showConfirmDialog(platformPanel, 
											  "Are you sure you want to activate the alarm?",
											  "Sound Alarm",
											  JOptionPane.YES_NO_OPTION);
			
			if(n == 0)
			{
				platformPanel.getPlatform().getWell(selected).getAlarm().ActivateAlarm();
				JOptionPane.showMessageDialog(platformPanel,
											  "Alarm sounded on well " + platformPanel.getPlatform().getWell(selected).getId() + "!");
			}
		}
	}
	
	class RealTimeCommentButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			realTimeCommentDialog = new RealTimeCommentDialog(platformPanel.getPlatform());
			
		}
	}
	
	

	
	
//	public static void main(String args[])
//	{
//		JFrame frame = new JFrame();
//		StatusPanel panel = new StatusPanel();
//		frame.getContentPane().add(panel);
//		frame.pack();
//		frame.setVisible(true);
//		//frame.setMinimumSize(new Dimension(200,300));
//		
//		frame.addWindowListener(new java.awt.event.WindowAdapter() {
//		    public void windowClosing(java.awt.event.WindowEvent winEvt) {
//		        System.exit(0); 
//		    }
//		});
//		
//	}

}
